package com.eduhzy.ttw.work.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.annotation.ScopeType;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.contract.WorkDetailContract;
import com.eduhzy.ttw.work.mvp.model.WorkDetailModel;
import com.eduhzy.ttw.work.mvp.model.entity.WorkDetailData;
import com.eduhzy.ttw.work.mvp.ui.adapter.WorkFileAdapter;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-1 16:08:41
 */
@Module
public class WorkDetailModule {
    private WorkDetailContract.View view;

    /**
     * 构建WorkDetailModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public WorkDetailModule(WorkDetailContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    WorkDetailContract.View provideWorkDetailView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    WorkDetailContract.Model provideWorkDetailModel(WorkDetailModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    WorkFileAdapter providerAdapter(List<WorkDetailData.FileListBean> lists) {
        return new WorkFileAdapter(lists);
    }

    @ActivityScope
    @Provides
    List<WorkDetailData.FileListBean> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    @ScopeType()
    RecyclerView.LayoutManager provideLayoutManager() {
        return new GridLayoutManager(view.getActivity(), 4);
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<WorkDetailData.HomeworkClassListBean, AutoBaseViewHolder> providerClassAdapter(List<WorkDetailData.HomeworkClassListBean> lists) {
        return new BaseQuickAdapter<WorkDetailData.HomeworkClassListBean, AutoBaseViewHolder>(R.layout.work_rv_item_class_detail, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, WorkDetailData.HomeworkClassListBean item) {
                helper.setText(R.id.tv_name, item.getClassName());
                helper.setGone(R.id.layout_submit, item.getOnline() == 1);
                helper.setText(R.id.tv_unread, (item.getTotalNum() - item.getReadNum()) + "人");
                helper.setText(R.id.tv_submit, item.getSubmitNum() + "人");
                helper.addOnClickListener(R.id.layout_submit);
                helper.addOnClickListener(R.id.layout_unread);

            }
        };

    }

    @ActivityScope
    @Provides
    List<WorkDetailData.HomeworkClassListBean> provideTeacherLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    @ScopeType(2)
    RecyclerView.LayoutManager provideTeacherLayoutManager() {
        return new LinearLayoutManager(view.getActivity());
    }


}